/**@FILE:WishAction.java
 * @AUTHOR:qingsheng.zheng
 * @DATE:2015-2-1 上午11:42:06*/
package com.xf.toy.web;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.xf.pub.exception.ServiceException;
import com.xf.pub.logger.LoggerUtil;
import com.xf.toy.bean.Wish;
import com.xf.toy.dao.page.Pagination;
import com.xf.toy.service.WishService;
import com.xf.toy.service.constant.ToyConst;
import com.xf.toy.web.common.BaseAction;

/*******************************************
 * @COMPANY:alibaba
 * @CLASS:WishAction
 * @DESCRIPTION:
 * @AUTHOR:qingsheng.zheng
 * @VERSION:v1.0
 * @DATE:2015-2-1 上午11:42:06
 *******************************************/
@Controller
@RequestMapping(value = "/toy/wish")
public class WishAction extends BaseAction {
	@Resource(name = "wishService")
	private WishService wishService;

	@RequestMapping(value = "/cancel" )
	public void wishcancel(@RequestParam Long wishid, HttpServletRequest req,
			HttpServletResponse resp) {
		try {
			operLogger.info(LoggerUtil.logstr("method", "toy/wish/cancel",
					"wishid", wishid + ""));
			Wish wish = new Wish();
			wish.setWishId(wishid);
			wish.setStatus(ToyConst.TOY_WISH_STATUS_CANCEL);
			wishService.updateWish(wish);
			response(resp, null);
		} catch (ServiceException e) {
			response(resp, e);
		}
	}

	@RequestMapping(value = "/product")
	public void wish(@RequestParam String toycode, @RequestParam Long userid,
			HttpServletRequest req, HttpServletResponse resp) {
		try {
			operLogger.info(LoggerUtil.logstr("method", "toy/wish/product",
					"userid", userid + "", "toycode", toycode));
			Wish wish = new Wish();
			wish.setToyCode(toycode);
			wish.setUserId(userid);
			wishService.userWish(userid, toycode);

			response(resp, null);
		} catch (ServiceException e) {
			response(resp, e);
		}
	}
	@RequestMapping(value = "/wishlist", method = RequestMethod.GET)
	public void wishlist(@RequestParam(required = false) Long userid,
			@RequestParam String status,
			@RequestParam(required = false) Integer pageNo,
			@RequestParam(required = false) Integer pageSize,
			HttpServletRequest req, HttpServletResponse resp) {
		try {
			Pagination page = new Pagination();
			if (pageNo != null) {
				page.setPageSize(pageSize);
				page.setCurrentPage(pageNo);
			}
			String[] statusArray = status.split(",");
			List<String> statuset = new ArrayList<String>();
			for (int i = 0; i < statusArray.length; i++) {
				statuset.add(statusArray[i]);
			}
			if ("w".equals(status)) {
				statuset.add(ToyConst.TOY_WISH_STATUS_ORDER);
			}
			operLogger.info(LoggerUtil.logstr("method", "toy/user/wishlist",
					"userid", userid + "", "stataus", status));
			List<Wish> wishs = wishService.selectUserWishs(userid, statuset,
					page);
			response(resp, wishs,page);
		} catch (ServiceException e) {
			response(resp, e);
		}
	}

	public void wishReturn(Long userid, @RequestParam Long order_id,
			HttpServletRequest req, HttpServletResponse resp) {

	}

}
